How do I add a header to a VB.NET 2008 SOAP request? [migrated]
Posted
by
robokev
on Programmers
See other posts from Programmers
or by robokev
Published on 2012-10-22T14:42:52Z
Indexed on
2012/10/22
17:18 UTC
Read the original article
Hit count: 220
soap
|visual-basic
I have a VB.NET 2008 program that accesses a Siebel web service defined by a WSDL and using the SOAP protocol.
The Siebel web service requires that a header containing the username, password and session type be included with the service request, but the header is not defined in the WSDL.
So, when I test the WSDL using the soapUI utility, the request as defined by the WSDL looks like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:lov="http://www.siebel.com/xml/LOVService" xmlns:lis="http://www.siebel.com/xml/ListQuery">
<soapenv:Header/>
<soapenv:Body>
<lov:EAILOVGetListOfValues_Input>
<lis:ListsQuery>
<lis:ListQuery>
<lis:Active>Y</lis:Active>
<lis:LanguageCode>ENU</lis:LanguageCode>
<lis:Type>CUT_ACCOUNT_TYPE</lis:Type>
</lis:ListQuery>
</lis:ListsQuery>
</lov:EAILOVGetListOfValues_Input>
</soapenv:Body>
</soapenv:Envelope>
But the above does not work because it contains an empty header that is missing user and session credentials. It only works if I manually replace <soapenv:Header/>
with a header containing the username, password, and session type as follows:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:lov="http://www.siebel.com/xml/LOVService" xmlns:lis="http://www.siebel.com/xml/ListQuery">
<soapenv:Header>
<UsernameToken xmlns="http://siebel.com/webservices">TESTUSER</UsernameToken>
<PasswordText xmlns="http://siebel.com/webservices">TESTPASSWORD</PasswordText>
<SessionType xmlns="http://siebel.com/webservices">None</SessionType>
</soapenv:Header>
<soapenv:Body>
<lov:EAILOVGetListOfValues_Input>
<lis:ListsQuery>
<lis:ListQuery>
<lis:Active>Y</lis:Active>
<lis:LanguageCode>ENU</lis:LanguageCode>
<lis:Type>CUT_ACCOUNT_TYPE</lis:Type>
</lis:ListQuery>
</lis:ListsQuery>
</lov:EAILOVGetListOfValues_Input>
</soapenv:Body>
</soapenv:Envelope>
My problem is that I cannot sort out how to translate the above into VB.NET 2008 code.
I have no problem importing the WSDL into Visual Studio 2008, defining the service in VB code and referencing the web service methods. However, I cannot sort out how to define the web service in VB such that the updated header in included in the web service request instead of the empty header. Consequently all my service requests from VB fail.
I can define a class that inherits from the SoapHeader class...
Public Class MySoapHeader : Inherits System.Web.Services.Protocols.SoapHeader
Public Username As String
Public Password As String
Public SessionType As String
End Class
...but how do I include this header in the SOAP request made from VB?
© Programmers or respective owner